<template>
  <jy-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="0px" class="top-left">
      <el-form-item label prop="guigxh">
        <el-input v-model="queryParams.guigxh" placeholder="请输入规格型号" clearable @keyup.enter.native="handleQuery" style="width: 160px" />
      </el-form-item>
      <el-form-item label prop="supId">
        <el-select v-model="queryParams.supId" filterable placeholder="请选择供应商">
          <el-option v-for="item in supList" :key="item.supId" :label="item.supName" :value="item.supId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label prop="inDate">
        <el-date-picker clearable v-model="queryParams.inDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择进场日期" style="width: 160px"></el-date-picker>
      </el-form-item>
      <el-form-item label prop="cunfwz">
        <el-input v-model="queryParams.cunfwz" placeholder="请输入存放位置" clearable @keyup.enter.native="handleQuery" style="width: 160px" />
      </el-form-item>
      <el-form-item label prop="pih">
        <el-input v-model="queryParams.pih" placeholder="请输入批号" clearable @keyup.enter.native="handleQuery" style="width: 160px" />
      </el-form-item>
      <el-form-item label prop="chucDate">
        <el-date-picker clearable v-model="queryParams.chucDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择出厂日期" style="width: 160px"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table border stripe ref="groupTable" v-loading="loading" :data="dataList" :highlight-current-row="true" @current-change="handleCurrentChange" row-key="tzId">
      <el-table-column width="50" label="选择" class-name="radio-border">
        <template slot-scope="scope">
          <el-radio :label="scope.row.tzId" v-model="tzId">{{ "" }}</el-radio>
        </template>
      </el-table-column>
      <el-table-column label="试验室" align="center" prop="deptName" min-width="120" show-overflow-tooltip />
      <el-table-column label="材料类型" align="center" prop="clType" min-width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cl_type" :value="scope.row.clType" />
        </template>
      </el-table-column>
      <el-table-column label="规格型号" align="center" prop="guigxh" min-width="120" show-overflow-tooltip />
      <el-table-column label="供应商" align="center" prop="supName" min-width="200" show-overflow-tooltip />
      <el-table-column label="产地厂家" align="center" prop="chandcj" min-width="200" show-overflow-tooltip />
      <el-table-column label="进场数量" align="center" prop="jincsl" min-width="120" show-overflow-tooltip />
      <el-table-column label="进场日期" align="center" prop="inDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="存放位置" align="center" prop="cunfwz" min-width="120" show-overflow-tooltip />
      <el-table-column label="批号" align="center" prop="pih" min-width="120" show-overflow-tooltip />
      <el-table-column label="出厂日期" align="center" prop="chucDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.chucDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="代表数量" align="center" prop="daibsl" min-width="120" show-overflow-tooltip />
      <el-table-column label="被试验次数" align="center" prop="syTimes" min-width="100" show-overflow-tooltip />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <div slot="footer" class="dialog-footer">
      <el-button size="small" type="primary" @click="submitForm">确 定</el-button>
      <el-button size="small" @click="cancel">取 消</el-button>
    </div>
  </jy-dialog>
</template>
<script>
import { listBsJctz } from "@/api/ycl/bsJctz";
import { listBsSup } from "@/api/ycl/bsSup";
import { mapGetters } from "vuex";
export default {
  name: "BsJctzView",
  dicts: ["cl_type"],
  data() {
    return {
      title: "样品来源选择",
      loading: false,
      open: false,
      total: 0,
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: undefined,
        guigxh: undefined,
        supId: undefined,
        inDate: undefined,
        cunfwz: undefined,
        pih: undefined,
        chucDate: undefined,
        tzStatus: undefined
      },
      tzId: undefined,
      currentInfo: {},
      supList: []
    };
  },
  // 监听顶部全局下拉
  computed: {
    ...mapGetters(["deptId"])
  },
  created() {},
  mounted() {},
  methods: {
    init(num) {
      this.open = true;
      this.handleQuery(num);
      this.getSupList();
    },
    /** 查询供应商列表 */
    getSupList() {
      let param = {
        pageNum: 1
      };
      listBsSup(param).then((response) => {
        this.supList = response.rows;
      });
    },
    /** 搜索按钮操作 */
    handleQuery(num) {
      this.queryParams.pageNum = 1;
      this.getList(num);
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查询原材料进场台账列表 */
    getList(num) {
      this.loading = true;
      listBsJctz({ ...this.queryParams, deptId: num }).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 选中
    handleCurrentChange(val) {
      this.currentInfo = val;
      this.tzId = val.tzId;
    },
    submitForm() {
      if (!this.currentInfo || !this.currentInfo.tzId) {
        this.$message.warning("请选择一个样品来源");
        return;
      }
      this.$emit("callBack", this.currentInfo);
      this.cancel();
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.dataList = [];
      this.tzId = undefined;
      this.currentInfo = {};
    }
  }
};
</script>
<style lang="scss" scoped>
::v-deep .radio-border .cell {
  display: flex;
  justify-content: center;
  padding-right: 0;
}
</style>
